package com.zzyk.main.model.vo;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class Message implements Serializable {
    public static final long serialVersionUID = 1L;

    // 执行结果
    private int code = 0;
    // 执行结果信息
    private String message;
    // 需要返回的数据
    private Map<String, Object> payload = new HashMap<>();

    public int getCode() {
        return code;
    }

    public Message setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public Message setMessage(String message) {
        this.message = message;
        return this;
    }

    public Map<String, Object> getPayload() {
        return payload;
    }

    public Message setPayload(Map<String, Object> payload) {
        this.payload = payload;
        return this;
    }

    public Object getData(String k) {
        return payload.get(k);
    }

    public Message addData(String k, Object v) {
        this.payload.put(k, v);
        return this;
    }

    public static Message success() {
        return success("操作成功");
    }

    public static Message success(String message) {
        Message msg = new Message();
        msg.code = 200;
        msg.message = message;
        return msg;
    }

    public static Message failed() {
        return failed("操作失败");
    }

    public static Message failed(String message) {
        Message msg = new Message();
        msg.code = 404;
        msg.message = message;
        return msg;
    }
}
